In modern communications technologies, based on a rapid increase in IP traffic, a QoS technology emerges to ensure user experience of a quality of service (Quality of Service, QoS) and becomes increasingly important. Traffic control is one of main technical means for implementing QoS. In a network processor chip, a user provides differentiated access rates and access bandwidths for users at different service levels through flexible configuration. Basically, in an existing traffic control technology, a token bucket algorithm is used as a basis, and common token bucket algorithms are a single rate three color mark algorithm (Single Rate Three Color Mark, SrTCM) in IETF RFC2697, a two rate three color mark algorithm (Two Rate Three Color Mark, TrTCM) in RFC2698, and an MEF10 algorithm evolved from the two algorithms.
The SrTCM is taken as an example. In this algorithm, three parameters are defined: a committed information rate (Committed Information Rate, CIR), a committed burst size (Committed Burst Size, CBS), and an excess burst size (Excess Burst Size, EBS). Generally, a structure of two buckets, that is, a C bucket and an E bucket, is set. A maximum depth of the C bucket is the CBS, a maximum depth of the E bucket is the EBS, and a token is generated only at a CIR rate. A token is firstly added to the C bucket, and CIR tokens are generated in a unit time; after the C bucket is full, a token is added to the E bucket; and when both the C bucket and the E bucket are filled up, a newly generated token will be discarded, and the number of tokens in the buckets no longer increases.
In color-blind mode, it is assumed that a packet length of an ingress is L, the number of tokens in the C bucket is Tc, and the number of tokens in the E bucket is Te,
if L<Tc, a packet is marked with green, and the number of tokens in the C bucket is reduced by L;
if Tc<L<Te, the packet is marked with yellow, and the number of tokens in the E bucket is reduced by L; and
if Te<L, the packet is marked with red, and both the number of tokens in the C bucket and the number of tokens in the E bucket are not reduced.
For example, at a time point t0, the number of tokens in the C bucket and the number of tokens in the E bucket are represented by using Tc(t0) and Te(t0), respectively. It is assumed that at a time point t1, a next data packet arrives. In this case, the number of increased tokens (assuming that the C bucket is not full) is ΔT×CIR within time ΔT (t1-t0). During design implementation, each time when a data packet arrives, the number of increased tokens and the number of tokens that needs to be subtracted when a packet passes need to be recalculated, and the current number of tokens in the C bucket and the current number of tokens in the E bucket are refreshed. Meanwhile, different colors are marked on packets. A processing procedure in color-aware mode is similar to that in color-blind mode, which is not repeated herein.
It can be seen from the foregoing traffic control process that when the total length of packets that arrive at an ingress within a unit time is greater than a CIR, because a speed of accumulating tokens is less than traffic when data arrives, according to the foregoing control result, a problem that most (even all) packets marked with green are short packets and most (even all) packets marked with red are long packets may occur. However, in an actual product application, a red packet is generally discarded. Therefore, the foregoing token bucket algorithm causes a problem that traffic imbalance occurs to long and short packets that have undergone traffic control.